/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#ifndef __CVARSYSTEM_H__
#define __CVARSYSTEM_H__


/*
 ==============================================================================

 Console Variables:

 CVars are used to hold string or numeric variables that can be changed or
 displayed at the console as well as accessed directly in the code.

 CVars are mostly used to hold settings that can be changed from the console or
 saved to and loaded from config files, but are also occasionally used to
 communicate information between different modules of the program.

 The user can access CVars from the console in three ways:
	cvarName			Prints the current value
	cvarName X			Sets the current value to X
	set cvarName X		Same as above, but creates the CVar if not present

 ==============================================================================
*/

// Creates the variable if it doesn't exist, or returns the existing one.
// If the variable exists, the flags will be OR'ed in, and if it has a latched
// value, the current value will be updated. If the variable has the CVAR_ROM
// flag set, the current value will be forced to the specified value. Both the
// reset value and the description will be updated.
// The description parameter can be NULL if you don't want it.
cvar_t *		CVar_Get (const char *name, const char *value, int flags, const char *description);

// Sets the value of a variable
void			CVar_SetString (cvar_t *cvar, const char *value);
void			CVar_SetFloat (cvar_t *cvar, float value);
void			CVar_SetInteger (cvar_t *cvar, int value);

// Finds a variable with the given name. Returns NULL if not found.
cvar_t *		CVar_FindVariable (const char *name);

// Command completion using a callback for each match
void			CVar_CompleteVariable (const char *partial, void (*callback)(const char *));

// Gets the value of a variable by name. Returns an empty string or zero if it
// doesn't exist.
const char *	CVar_GetVariableString (const char *name);
float			CVar_GetVariableFloat (const char *name);
int				CVar_GetVariableInteger (const char *name);

// Sets the value of a variable by name. Creates the variable if it doesn't
// exist.
void			CVar_SetVariableString (const char *name, const char *value);
void			CVar_SetVariableFloat (const char *name, float value);
void			CVar_SetVariableInteger (const char *name, int value);

// Writes lines containing "seta variable value" to the given file for all the
// variables with the CVAR_ARCHIVE flag set.
// Used for config files.
void 			CVar_WriteArchiveVariables (fileHandle_t f);

// If allowCheats is false, all variables with the CVAR_CHEAT flag set will be
// forced to their default values. Otherwise the user will be able to change
// CVAR_CHEAT variables from the console or config files.
void			CVar_FixCheatVariables (bool allowCheats);

// Returns true if cheats are allowed, false otherwise
bool			CVar_AllowCheats (void);

// Gets flags that tell what kind of variables have been modified
int				CVar_GetModifiedFlags (void);

// Sets flags that tell what kind of variables have been modified
void			CVar_SetModifiedFlags (int flags);

// Clears flags to allow detecting another modification to variables
void			CVar_ClearModifiedFlags (int flags);

// Called by the command system when argv[0] doesn't match a known command.
// Returns true if the command was a variable reference that was handled (print
// or change).
bool			CVar_Command (void);

// Returns an info string containing all the CVAR_USERINFO variables
const char *	CVar_UserInfoString (void);

// Returns an info string containing all the CVAR_SERVERINFO variables
const char *	CVar_ServerInfoString (void);

// Initializes the cvar system
void			CVar_Init (void);

// Shuts down the cvar system
void			CVar_Shutdown (void);


#endif	// __CVARSYSTEM_H__
